package cn.com.headfree.version.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.headfree.base.controller.ExBaseController;
import cn.com.headfree.base.controller.ResultData;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.version.service.IVersionService;
import cn.com.headfree.vo.version.VersionVo;
import cn.com.headfree.workflow.controller.WorkFlowController;

@Controller
@RequestMapping(value = "/version", produces = "application/json;charset=UTF-8")
public class VersionController extends ExBaseController {

	private static final Logger LOG = LogManager.getLogger(VersionController.class);

	@Autowired
	private IVersionService versionService;

	/**
	 * 查询版本信息
	 * 
	 * @param versionNo
	 * @return
	 */
	@RequestMapping("/getVersions")
	@ResponseBody
	public ResultData getVersions(String versionNo, HttpServletRequest request) {
		ResultData result = new ResultData();
		try {
			List<VersionVo> list = versionService.getVersions(versionNo);
			result.setData(list);
			LOG.info("查询版本列表成功！");
		} catch (Exception e) {
			result.setErrorMsg("查询版本列表异常");
			result.setSuccess(false);
			LOG.error("查询版本列表异常", e);
		}
		return result;
	}

	/**
	 * 版本添加
	 * 
	 * @param versionNo
	 * @param request
	 * @return
	 */
	@RequestMapping("/addVersion")
	@ResponseBody
	public ResultData addVersion(VersionVo versionVo, HttpServletRequest request) {
		ResultData result = new ResultData();
		try {
			versionService.addVersion(versionVo);
			result.setData("版本添加成功！");
			LOG.info("版本添加成功！");
		} catch (Exception e) {
			result.setErrorMsg("版本添加异常");
			result.setSuccess(false);
			LOG.error("版本添加异常", e);
		}
		return result;
	}
	
	
	
	@RequestMapping("/getNotice")
	@ResponseBody
	public ResultData getNotice( HttpServletRequest request) {
		ResultData result = new ResultData();
		try {
			User user = this.getLoginUserInfo(request);
			List<VersionVo> versions=versionService.getNotice(user.getFax());
			result.setData(versions);
			LOG.info("版本提醒数据返回成功！");
		} catch (Exception e) {
			result.setErrorMsg("版本提醒数据返回异常");
			result.setSuccess(false);
			LOG.error("版本提醒数据返回异常", e);
		}
		return result;
	}

}
